<?php
namespace lib;

class Controller{

    /**
     * @var Request
     */
    protected $request;
    /**
     * @var View
     */
    protected $view;

	/**
	 * Controller constructor.
	 * @param Request $request
	 */
    function __construct(Request $request){
        $this->request = $request;
        $this->view = new View();
    }

    protected function data($key = ''){
        return $this->request->data($key);
    }

    /**
     * 模板赋值
     * @param $key
     * @param $val
     * @return mixed
     */
    protected function set($key, $val){
        return $this->view->set($key, $val);
    }

    /**
     * 渲染模板
     * @param string $file
     * @return string
     * @throws \Exception
     */
    protected function fetch($file = ''){
        return $this->view->fetch($file);
    }

}